//
//  Utils.m
//  NvSellerShow
//
//  Created by Meicam on 2017/2/25.
//  Copyright © 2017年 Meicam. All rights reserved.
//

#import "Utils.h"

@implementation Utils
+ (instancetype)sharedUtils {
    static Utils *_instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[Utils alloc] init];
    });
    
    return _instance;
}


+ (BOOL)checkFileExist:(NSString *)clipPath {
    if([clipPath hasPrefix:@"file://"]) {
        clipPath = [clipPath substringFromIndex:7];
    }
    NSFileManager * fileManager = [NSFileManager defaultManager];
    return [fileManager fileExistsAtPath:clipPath];
}

+ (NSString *)stringWithTime:(NSTimeInterval)second{
    NSDate *d = [NSDate dateWithTimeIntervalSince1970:second];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    if (second/3600 >= 1) {
        [formatter setDateFormat:@"HH:mm:ss"];
    } else {
        [formatter setDateFormat:@"mm:ss"];
    }
    return [formatter stringFromDate:d];
}

+ (NvsTimeline *)createTimeLine:(NvSSVideoCreateScale)editMode {
    NvsStreamingContext *streamingContext = [NvsStreamingContext sharedInstanceWithFlags:NvsStreamingContextFlag_Support4KEdit];
    
    NvsVideoResolution videoEditRes;
    if(editMode == NvSSVideoCreateScaleSquare) {
        videoEditRes.imageWidth = 720;
        videoEditRes.imageHeight = 720;
    } else if(editMode == NvSSVideoCreateScaleHorizontal){
        videoEditRes.imageWidth = 1280;
        videoEditRes.imageHeight = 720;
    } else {
        videoEditRes.imageWidth = 720;
        videoEditRes.imageHeight = 1280;
    }
    videoEditRes.imagePAR = (NvsRational){1, 1};
    NvsRational videoFps = {25, 1};
    NvsAudioResolution audioEditRes;
    audioEditRes.sampleRate = 48000;
    audioEditRes.channelCount = 2;
    audioEditRes.sampleFormat = NvsAudSmpFmt_S16;
    
    return [streamingContext createTimeline:&videoEditRes videoFps:&videoFps audioEditRes:&audioEditRes];
}
@end
